<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        document.cookie="user1=p"
        document.cookie="user2=i"
        document.cookie="user3=o"
        console.log(document.cookie)

        //读取特定的cookie
        function getcookie(name){
             var cookies=document.cookie.split(';')//分割成字符串的数组
             //console.log(cookies)
             name=name+'='
            console.log(name)
             for(var i=0;i<cookies.length;i++){
                var cookie =cookie=cookies[i].trim()
                //移除字符串两侧空白
                
                //console.log(cookie)
                if(cookie.indexOf(name)==0)
                //返回指定字符串在字符串中首次出现的位置
                return cookie.substring(name.length,cookie.length)
                //需要提取字串的起始位置
             }
             return "";

        }
        var cookievalue = getcookie('user2')//你想要获取cookie的名称
        //console.log(cookievalue)
    </script>
</body>
</html>